# utils.py
import requests
from datetime import datetime

def get_session_with_login(username, password):
    from config_heima import API_URLS
    session = requests.Session()
    login_data = {
        'loginName': username,
        'password': password
    }
    try:
        response = session.post(API_URLS["login"], data=login_data)
        if response.status_code == 200:
            result = response.json()
            if result.get('success'):
                # 登录成功
                token = result['resultObject']['token']
                return session, token, result['resultObject'], None
            else:
                # 登录失败，返回错误信息
                error_msg = result.get('errorMessage', '登录失败')
                return None, None, None, error_msg
        else:
            return None, None, None, f"请求失败，状态码：{response.status_code}"
    except Exception as e:
        return None, None, None, f"请求出错：{str(e)}"

def get_headers(token):
    return {
        'Token': token,
        'Content-Type': 'application/x-www-form-urlencoded'
    }





